<?php

class MailRobot{
	
	public static function mailGonder($email,$message,$subject='BYE'){
		if(empty($email)) return 0;
		$giden = new EpostaGidecek();
		$giden->eposta = $email;
		$giden->konu = $subject;
		$giden->mesaj = $message;
		$giden->save();
		
	}

	public static function gonder(){
		$eposta = EpostaGidecek::model()->find();
		if(!empty($eposta)){
			$client = new nusoap_client('https://mail.anadolu.edu.tr/anadoluad/anadoluad.asmx?WSDL',true);
			$giden = new EpostaGiden();
			$giden->eposta = $eposta->eposta;
			$giden->konu = $eposta->konu;
			$giden->mesaj = $eposta->mesaj;
			$giden->zaman = time();
			
			$message = nl2br($eposta->mesaj); 
			$message .= "<br /><br />bye.anadolu.edu.tr";


			$param=array('SID'=>'7552220047703314535485841322110067017830107564253246127160178783',
					'optionalSubject'=>$eposta->konu,
					'optionalFromName'=>'BYE',
					'ToAddress'=>$eposta->eposta,
					'MessageBody'=>$message
			);
			$client->soap_defencoding = "UTF-8";
			//Araclar::trace($param);
			$result = $client->call('Mail_SendMailFromRobot', $param, '', '', false, true);
			//Araclar::trace($result);
			$eposta->delete();
			$giden->save();
		}
	}	
}
?>
